package com.gaofei.orders.controller;


import com.gaofei.orders.domain.OrderTbl;
import com.gaofei.orders.feign.AccountFeign;
import com.gaofei.orders.service.IOrderTblService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaofei
 * @since 2021-05-29
 */
@RestController
@RequestMapping("/orderTbl")
public class OrderTblController {

    @Autowired
    IOrderTblService orderTblService;

    @Autowired
    AccountFeign accountFeign;

    @RequestMapping("createOrder")
    public String create(String uid,String commonCode,int count){
        //只是创建订单
        OrderTbl orderTbl = new OrderTbl();
        orderTbl.setCommodityCode(commonCode);
        orderTbl.setUserId(uid);
        orderTbl.setCount(count);
        orderTbl.setMoney(count * 100);
        orderTblService.save(orderTbl);

        //调用账户服务来－钱
        accountFeign.reduce(uid,count*100);
        return "订单创建成功";
    }
}

